﻿@model FCDB.Entity.FormExpense
@using FB.Extensions;
@{
    ViewBag.Title = "费用报销审批单";
    Layout = "~/Views/Shared/_FormLayout.cshtml";
    var IsViewMode = Model.Status != (short)FCDB.Entity.FormStatusEnum.Empty && Model.Status != (short)FCDB.Entity.FormStatusEnum.Draft;
}

@section HeadIncluder 
{
    <link href='@Url.Content("~/Content/public.css")' rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")' rel="stylesheet" /> 
}
    @{
        Html.RenderPartial("UCFormButtonBar", Model);
        }
    <div class="frombox" id="formMain">
        <div class="from_l" style="background: #fff;">
            <div class="left_con_f PrintArea">
                  
                <div align="center" class="left_f_tit">费用报销审批单</div>
                @using (Html.BeginForm("SaveFormExpense", "Form", FormMethod.Post, new { id = "frm" }))
                {
                    
                    Html.RenderPartial("UCHiddenArea"); 
                    <table width="100%" class="left_xx" id="myTable">
                        <tr>
                            <td class="text_w" align="center">流程名称：
                            </td>
                            <td colspan="7">
                                @if (IsViewMode){
                                    @Model.FormTitle
                                }else{
                                <input id="txtFormTitle" style="width:98%;"  class="validate[required] in_c1 " type="text"  name="FormTitle"    value="@Model.FormTitle"/>
                                }
                            </td>
                        </tr>
                        <tr>
                            <td class="text_w" align="center" style="width: 66px">表单序号</td>
                            <td>
                                @if (IsViewMode)
                                {
                                    @Model.FormNumber
                                }
                                else
                                {
                                    <input   type="text" id="FormNumber"  style="width:66px" value="@Model.FormNumber" readonly="ture"  class="in_c1" name="FormNumber" />
                                }
                            </td>
                            <td class="text_w" align="center" style="width: 66px">部门</td>
                            <td>
                                @if (IsViewMode)
                                {
                                    @ViewBag.DepartmentName
                                }
                                else
                                {
                                    <input   type="text" disabled="disabled"  style="width:66px" id="DepartmentName" class="in_c1" value="@ViewBag.DepartmentName" name="DepartmentName"   />
                                    <input id="DepartmentID" type="hidden"  name="DepartmentID" value="@Model.DepartmentID" />
                                }
                            </td>
                            <td class="text_w" align="center" style="width: 66px">填单人</td>
                            <td>
                                @if (IsViewMode)
                                {
                                    @ViewBag.UserName
                                }
                                else
                                {
                                    <input   type="text" disabled="disabled"  style="width:66px"  class="in_c1" id="ApplyUserName" value="@ViewBag.UserName" name="ApplyUserName"   />
                                    <input id="ApplyUserID" type="hidden"  name="ApplyUserID" value="@Model.ApplyUserID" />
                                }
                            </td>
                            <td class="text_w" align="center" style="width: 66px">领款人 <a style="color: red; position: relative; top: 3px">*</a> </td>
                            <td>
                                @if (IsViewMode)
                                {
                                    @Model.ReceiveUser
                                }
                                else
                                {
                                    <input type="text"  class="validate[required] in_c1 "  style="width:66px"  id="ReceiveUser"  value="@ViewBag.UserName"  name="ReceiveUser"  style=" height:25px; font-size:12px"  />
                                }
                            </td>
                        </tr>
                        <tr>
                            <td class="text_w" align="center">填单时间 <a style="color: red; position: relative; top: 3px">*</a> </td>
                            <td  colspan="2">
                                 @if (IsViewMode)
                                {
                                    @Model.FormDate.Value.ToString("yyyy-MM-dd")
                                }
                                else
                                {
                                <input  type="text" id="FormDate"  style="width:66px" name="FormDate" class="in_c1" readonly="true" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                                 }
                            </td>
                            <td class="text_w" align="center">发票张数 <a style="color: red; position: relative; top: 3px">*</a> </td>
                            <td>
                                 @if (IsViewMode)
                                {
                                    @Model.Number
                                }
                                else
                                {
                                <input   type="text"   style="width:66px" id="Number" value="@Model.Number" name="Number" style="height:25px; font-size:12px" class="validate[required] validate[custom[onlyNumber]] in_c1" />
                                 }
                            </td>
                            <td class="text_w" align="center"colspan="2">是否授信 <a style="color: red; position: relative; top: 3px">*</a> </td>
                            <td>
                                 @if (IsViewMode)
                                {
                                    @(Model.IsEnable.Value ? "是" : "否")
                                }
                                else
                                {
                                <select id="IsEnable" name="IsEnable" class="validate[required] in_c1"  style="width:66px">
                                    <option value="true">是</option>
                                    <option value="false">否</option>
                                </select>
                                 }
                            </td>
                        </tr>
                    </table>
                    <table id="otbl" width="100%" class="left_xx">
                        <tr>
                            <th style=" text-align:center; font-weight:bold ">序号</th>
                            <th style=" text-align:center; font-weight:bold ">费用说明</th>
                            <th style=" text-align:center; font-weight:bold ">金额</th>
                        </tr>
                        @{ 
                    IList<FCDB.Entity.FormExpenseItem> itemList = (IList<FCDB.Entity.FormExpenseItem>)ViewBag.FormExpenseItemList;
                    for (int i = 0; i < 5; i++)
                    {
                         if (itemList.Count > i)
                          {
                            var item = itemList[i];
                            <tr>
                                <td style="text-align:center">@(i + 1)</td>
                                <td >
                                     @if (IsViewMode)
                                {
                                    @item.Expense
                                         <input  type="hidden"    name="Expense" value="@item.Expense"/>
                                }
                                else
                                {
                                    <input  type="text"   class="in_c1  Expense" name="Expense" value="@item.Expense"/>
                                     }
                                </td>
                                <td>
                                     @if (IsViewMode)
                                {
                                    @item.Due
                                         <input  type="hidden"     name="Due" value="@item.Due" />
                                }
                                else
                                {
                                    <input  type="text"   class="in_c1 in_center validate[custom[number]]"    name="Due" value="@item.Due" onchange="rowSum()" />
                                     }
                                </td>
                            </tr>

                        }
                    else
                    {
                              <tr>
                                <td style="text-align:center">@(i + 1)</td>
                                <td>
                                    @if (!IsViewMode)
                                {
                                    <input type="text" class="in_c1  Expense" style="width:98%" name="Expense" />
                                    }
                                </td>
                                <td >
                                    @if (!IsViewMode)
                                {
                                    <input type="text" class="validate[custom[number]] in_c1 in_center " style="width:98%" name="Due" onchange="rowSum()" />
                                    }
                                </td>
                             
                            </tr>
                         }
                    }
                        }
                    </table>
                     
                    <table width="100%" class="left_xx">
                        <tr>
                            <td class="text_w" align="center">总计小写</td>
                            <td>
                                 @if (IsViewMode)
                                {
                                     @Html.formatCash(Model.LowerWord)
                                        <input  type="hidden" id="txtLowerWord" name="LowerWord" value="@Model.LowerWord"/> 
                                }
                                else
                                {
                                <input type="text"  readonly="true" id="LowerWord"  value="@Model.LowerWord"  class="in_c1" name="LowerWord"    />
                                 }
                            </td>

                            <td class="text_w" align="center">大写：</td>
                            <td>
                                 @if (IsViewMode)
                                {
                                    @Model.UpWord
                                }
                                else
                                {
                                <input type="text"   id="UpWord"  value="@Model.UpWord" readonly="true" class="in_c1"  name="UpWord"  style="width:200px"  />
                                 }
                            </td>
                        </tr>
                        <tr>
                           <td class="text_w" align="center">归属公司<a style="color: red; position: relative; top: 3px">*</a> </td>
                            <td colspan="5">
                                 @if (IsViewMode)
                                {
                                    @Model.BillType 
                                    <input  type="hidden" id="txtBillType" name="BillType" value="@Model.BillType"/> 
                                    
                                }
                                else
                                {
                                <select id="BillType" style="width: 90%" name="BillType" class="validate[required] in_c1 " >
                                   <option  value=""></option>
                                 @foreach (var item in FCDB.Repository.ConfigHelper.FinaceCompanyList)
                                 {
                                   <option  @(Model.BillType==item.CompanyName?"selected":"") value="@item.CompanyName">@item.CompanyName</option>
                                 }
                               </select>
                                 }
                                </tr>
                            <tr>
                        <td class="text_w" align="center">最终审批人  </td>
                        <td colspan="5">
                            @if (IsViewMode)
                            {
                                <input name="EndChecker" type="radio"  disabled="disabled" value="财务总监" /><i>财务总监</i>
                                <input name="EndChecker" type="radio"  disabled="disabled" value="总经理助理" /><i>总经理助理</i>
                                <input name="EndChecker" type="radio"  disabled="disabled" value="总经理"  /><i>总经理</i>
                                <input name="EndChecker" type="radio"  disabled="disabled" value="终审"  /><i>终审</i>
                            }
                            else
                            {
                                <input name="EndChecker" type="radio"  disabled="disabled" value="财务总监" /><i>财务总监</i>
                                <input name="EndChecker" type="radio"  disabled="disabled" value="总经理助理" /><i>总经理助理</i>
                                <input name="EndChecker" type="radio"  disabled="disabled" value="总经理"  /><i>总经理</i>
                                <input name="EndChecker" type="radio"  disabled="disabled" value="终审"  /><i>终审</i>
                            }
                        </td>
                    </tr>
                        <tr class="printArea_disable">
                             <td class="text_w" align="center">备注 <a style="color:red;position:relative; top:3px">*</a></td>
                           <td colspan="5">
                                   @if (IsViewMode)
                                   {
                                       @Html.ApplyBR(Model.Remark)
                                   }else{
                                <textarea id="Remark" class="in_c1" name="Remark" cols="40" rows="4" style="width: 88%; font-size: 12px">@Model.Remark</textarea>
                                 }
                            </td>
                        </tr>
                    </table>
                } 
                   <form style="display:none" action="@Url.Action("SaveFormExpenseBillDue", "Form")" id="frmExpenseBillDueConfirm">
                    <input  type="hidden"  name="ProcessGuid" value='@Request["ProcessGuid"]' />
                    <input   type="hidden"  name="ID" value="@Model.ID" />
                    <input  type="hidden"  name="FormGuid" value="@Model.FormGuid" />
                    <input   type="hidden"  name="Status" value="@Model.Status" />
                    <table style="width: 100%; height: 36px; border: none;">
                        <tr>
                             <td  style="border-bottom: none; border-top: none; border-right: none; width: 151px;">出纳</td>
                            <td>实付金额:
                                @if(Model.BillDue.HasValue)
                                {
                                    <span> @Html.formatCash(Model.BillDue.Value.ToString()) </span>
                                }else
                                {
                                <input     type="text" id="txtBillDue" name="BillDue"  value="@Model.BillDue" />   
                                }
                                 备注:
                                 @if (!String.IsNullOrEmpty(Model.CashierRemark))
                                {
                                    @Model.CashierRemark
                                }
                                else
                                { 
                                    <input   style="width:160px;height:20px;"   type="text" id="txtCashierRemark" name="CashierRemark"  value="@Model.CashierRemark" />
                                }
                                @* <span class="btn_s3 btn_c1"><button type="button" onclick="CreateExpense()" class="fj btn_c3 btn_s">费用分拆</button></span>*@
                            </td>
                        </tr> 
                    </table>
                </form>
                 <form style="display:none" action="@Url.Action("SaveFormExpenseWritter", "Form")" id="frmWritterConfirm">
                    <input  type="hidden"  name="ProcessGuid" value='@Request["ProcessGuid"]' />
                    <input   type="hidden"  name="ID" value="@Model.ID" />
                    <input  type="hidden"  name="FormGuid" value="@Model.FormGuid" />
                    <input   type="hidden"  name="Status" value="@Model.Status" />
                    <table style="width: 100%; height: 36px; border: none;">
                        <tr>
                             <td  style="border-bottom: none; border-top: none; border-right: none; width: 151px;">领款人签名</td>
                            <td>
                                  @if(String.IsNullOrEmpty(Model.Writter))
                                  {
                                       <input     type="text" id="txtWritter" name="Writter"  value="@Model.Writter" /> 
                                  }
                                  else
                                  {
                                      <span>@Model.Writter</span>
                                  }
                            </td>
                        </tr> 
                    </table>
                </form>
                @{
                    Html.RenderPartial("UCFormCheckLog");
                }
           </div>
        </div>
        @{
            Html.RenderPartial("UCRightArea");
        } 
    </div>
 
<script src=@Url.Content("/Scripts/jquery.form.js") type="text/javascript"></script>
<script src=@Url.Content("/Scripts/foa.form.js?v=20140904") type="text/javascript"></script>
<script type="text/javascript">
    function initForm() {
        $("#frm").validationEngine({ promptPosition: "topLeft" });
        $("#txtApplyDate").kendoDatePicker({ format: "yyyy-MM-dd" });
        $("#BillType").val("@Model.BillType");
        $("#Type").val("@Model.Type");
        $("#IsEnable").val("@Model.IsEnable");
        var ProccessActiveContainerList = $(".ProccessActiveContainer");
        if (ProccessActiveContainerList.length > 0) {
            $.each(ProccessActiveContainerList, function (i, item) {
                var divId = $(item).attr("id");
                var frmID = divId.slice(3);
                $("#" + frmID).appendTo(item);
                $("#" + frmID + " input").attr("disabled", "disabled");
                $("#" + frmID + " button").attr("disabled", "disabled");
                $("#" + frmID).show();
            });
            $(".curentContainer form input").removeAttr("disabled");
            $(".curentContainer form button").removeAttr("disabled");
        }
    }
    function rowSum() {
        var item = document.getElementsByName("Due");
        var sum = 0;
        for (var i = 0; i < item.length; i++) {
            sum += item[i].value * 1;
        }
        sum = sum.toFixed(2);
        $("#LowerWord").val(sum);
        var num = Arabia_to_Chinese($("#LowerWord").val());
        $("#UpWord").val(num);
        var FormTitle = '@Model.FormTitle';
        $("#txtFormTitle").val(FormTitle + "--金额:" + $("#LowerWord").val());
    }
    $(function () { 
        initForm(); 
    });
    function Save() {
        var formStatus = $("#hStatus").val();
        if (formStatus == "0" || formStatus == "1") {
            var flag = $('#frm').validationEngine('validate');
            if (!flag) return false;
            GetProcessCheckUser(null, null, function (selectPostList) {
                if (selectPostList != null || selectPostList != undefined) {
                    var arr = new Array();
                    $.each(selectPostList.UserIDList, function (i, item) {
                        var obj = new Object();
                        obj.Key = item.UserID;
                        obj.Value = item.Name;
                        arr.push(obj);
                    });
                    selectPostList.UserIDList = arr;
                    var checkUserList = selectPostList;
                    if (checkUserList == null) return;
                    var FormConditionValue = JSON.stringify(GetFormCondition());
                    var options = {
                        data: {
                            FormAttachement: GetFormAttachement(), FormsRelation: GetFormsRelation(),
                            CheckLogUser: JSON.stringify(checkUserList.UserIDList),
                            NextActivityGuid: checkUserList.ActivityGuid, FormConditionValue: FormConditionValue
                        },
                        success: function (data) {
                            alert("表单发送成功");
                            window.close();
                        }
                    };
                    $("#hStatus").val("2");
                    $("#frm").ajaxSubmit(options);
                }
            });

        }
        else {
            submitCheckLog();
        }
    }



    function Save() {
        var formStatus = $("#hStatus").val();
        if (formStatus == "0" || formStatus == "1") {
            var flag = $('#frm').validationEngine('validate');
            if (!flag) return false;
            GetProcessCheckUser(null, null, function (selectPostList) {
                if (selectPostList != null || selectPostList != undefined) {
                    var arr = new Array();
                    $.each(selectPostList.UserIDList, function (i, item) {
                        var obj = new Object();
                        obj.Key = item.UserID;
                        obj.Value = item.Name;
                        arr.push(obj);
                    });
                    selectPostList.UserIDList = arr;
                    var checkUserList = selectPostList;
                    if (checkUserList == null) return;

                    var FormTravelExpenseItemList = new Array();
                    var rows = $("#otbl tr:gt(0)");
                    $.each(rows, function (i, item) {
                        var Expense = $(item).find("input[name='Expense']").val();
                        if (Expense == "") return;
                        var obj = new Object();
                        obj.Expense = $(item).find("input[name='Expense']").val();
                        obj.Due = $(item).find("input[name='Due']").val();
                        obj.ExpenseType = $(item).find("select[name='ExpenseType']").val();
                        FormTravelExpenseItemList.push(obj);
                    });
                    var FormConditionValue = JSON.stringify(GetFormCondition());
                    var ItemsListString = JSON.stringify(FormTravelExpenseItemList);
                    var options = {
                        data: {
                            FormAttachement: GetFormAttachement(), FormsRelation: GetFormsRelation(),
                            ItemsListString: ItemsListString, CheckLogUser: JSON.stringify(checkUserList.UserIDList),
                            NextActivityGuid: checkUserList.ActivityGuid, FormConditionValue: FormConditionValue
                        },
                        success: function (data) {
                            alert("表单发送成功");
                            window.close();
                        }
                    };
                    $("#hStatus").val("2");
                    $("#frm").ajaxSubmit(options);
                }
            });
        }
        else {
            submitCheckLog();
        }
    }
    function SaveAsDraft() {
        var flag = $('#frm').validationEngine('validate');
        var FormTravelExpenseItemList = new Array();
        var rows = $("#otbl tr:gt(0)");
        $.each(rows, function (i, item) {
            var Expense = $(item).find("input[name='Expense']").val();
            if (Expense == "") return;
            var obj = new Object();
            obj.Expense = $(item).find("input[name='Expense']").val();
            obj.Due = $(item).find("input[name='Due']").val();
            obj.ExpenseType = $(item).find("select[name='ExpenseType']").val();
            FormTravelExpenseItemList.push(obj);
        });
        var ItemsListString = JSON.stringify(FormTravelExpenseItemList)
        var options = {
            data: { FormAttachement: GetFormAttachement(), FormsRelation: GetFormsRelation(), ItemsListString: ItemsListString },
            success: function (data) {
                alert("表单保存成功");
                window.close();
            }
        };
        $("#hStatus").val("1");
        $("#frm").ajaxSubmit(options);
    }
    function CreateExpense() {
        var FormTravelExpenseItemList = new Array();
        var rows = $("#otbl tr:gt(0)");
        $.each(rows, function (i, item) {
            var Remark = $(item).find("input[name='Expense']").val();
            if (Remark == "" || Remark==undefined) return;
            var obj = new Object();
            obj.Remark = $(item).find("input[name='Expense']").val();
            obj.Due = $(item).find("input[name='Due']").val();
            obj.AppInstanceID = " @Model.FormNumber";
            FormTravelExpenseItemList.push(obj);
        });
        var FormListString = JSON.stringify(FormTravelExpenseItemList);
        var url = "@Url.Action("CreateByOA", "OAFormFinace")?FormListString=" + FormListString;
        OpenPop(url,"费用分拆表");
    }

    function OpenPop(url, titleName, width, height) {
        width = width || 1000;
        height = height || 600;
        window.top.winObj = window;
        window.top.refresh = onRefresh;
        window.top.oDG1 = $.dialog({
            lock: true,
            background: '#FFF',
            opacity: 0.2,
            id: 'esDialog',
            title: titleName,
            titleAlign: 'left',
            content: "url:" + url,
            width: width,
            height: height,
            btnBar: false,
            lockScroll: true
        });
    }
    function onRefresh(typeid) {
        $("#CreateExpense").html("费用分拆表（已）");
    }
</script>